home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 2.9 KB | 92 lines | [TEXT/GEOL] |
- Item 4527159 24-Jan-91 10:40PST
-
- From: D3861 Electronics for Imaging,Avi Bar,PRT
-
- To: POWERUP.ENG Power Up Software,PRT
- MACAPP.TECH$ MacApp Technical
-
- ------------------------------------------------------------------------------
-
- Sub: Re: Failure Handling
-
- James et al. --
-
- >no one seems to override TApplication.ShowError() to post any
- >fancy error alerts.
-
- I recently overrode TApplication.ShowError to add the error number to the
- dialog in one of the corners (much like Photoshop does). We expect this to be
- very useful in gathering error information from beta testers and end users.
- (Although even more important is to provide sensible error string resources; it
- baffles me completely why Apple didn't include a real 'errs' resource and the
- associated 'STR#'. I have had to add something like this to nearly every Mac
- application I've written.) Unfortunately, the default mechanism goes through a
- few levels of global routine, so it requires taking the code from the final
- global routine and pasting it into your TApplication.ShowError override. This
- is particularly unfortunate because it means I can't just distribute the hack,
- because it includes a significant amount of MacApp source code.
-
- I can give you it in pieces. Here's the alert filter:
-
- {$S MAError}
-
- var
- theError: integer;
-
- function MyErrAlertFilter (theDialog: DialogPtr; var theEvent: EventRecord;
- var itemHit: INTEGER): BOOLEAN;
- var
- s: Str255;
- r: Rect;
- info: FontInfo;
- oldFont, oldSize: integer;
- oldFace: Style;
- save: GrafPtr;
- begin
- MyErrAlertFilter := MacAppAlertFilter(theDialog, theEvent, itemHit);
- if (theEvent.what = updateEvt) & (theError <> noErr) then
- begin { draw the error number in the lower left-hand corner }
- GetPort(save);
- SetPort(theDialog);
- oldFont := theDialog^.txFont;
- oldSize := theDialog^.txSize;
- oldFace := theDialog^.txFace;
- TextFont(applFont);
- TextSize(9);
- TextFace([]);
- GetFontInfo(info);
- NumToString(theError, s);
- r := theDialog^.portRect;
- r.left := r.left + 4;
- r.bottom := r.bottom - 4;
- r.top := r.bottom - (info.ascent + info.descent);
- r.right := r.left + StringWidth(s);
- TextBox(@s[1], length(s), r, teJustLeft);
- TextFont(oldFont);
- TextSize(oldSize);
- TextFace(oldFace);
- SetPort(save);
- end;
- end;
-
- The ShowError override is just exactly like ErrorAlert, except that the line:
-
- StdAlert(alertID);
-
- is changed to:
-
- theError := error;
- reply := MacAppAlert(alertID, ProcPtr(@MyErrAlertFilter));
-
- (Oh, and TApplication.ShowError calls its first argument "error", while
- ErrorAlert calls it "err", so I did a search-and-replace in the copied
- ErrorAlert code to change the argument name.)
-
- > no one seems to call Failure() directly
-
- I do frequently, for various bad parameter and such like errors.
-
- Tim Maroney
- Electronics for Imaging
-
-